<template>
  <div class="details_container">
    <!-- 详情页轮播图 -->
    <div class="details_swiper">
      <van-swipe class="my-swipe" :autoplay="3000" indicator-color="white">
        <van-swipe-item v-for="(item,index) in item.pics" :key="index">
          <img :src="item.pic" alt />
        </van-swipe-item>
      </van-swipe>
    </div>
    <!-- 详情页信息 -->
    <div class="details_message_container">
      <div class="details_message_wrapper">
        <div class="details_message_name" v-html="item.basicInfo.name"></div>
        <div class="details_message_title" v-html="item.basicInfo.characteristic"></div>
        <div class="details_message_box">
          <div class="details_message_price">低价￥{{item.basicInfo.minPrice}}</div>
          <div class="details_message_gray">
            <span>原价￥{{item.basicInfo.originalPrice}}</span>
            <span>库存{{item.basicInfo.stores}}</span>
          </div>
        </div>
      </div>
    </div>
    <div class="gray_line"></div>
    <!-- 商品介绍评价 -->
    <div class="details_main_container">
      <div class="details_button_container">
        <div class="details_introduce_button">商品介绍</div>
        <div class="details_evaluate_button">商品评价</div>
      </div>
      <!-- 商品介绍 -->
      <div class="details_introduce_content" v-html="item.content"></div>
      <!-- 商品评价 -->
      <div class="details_introduce_content"></div>
    </div>
    <!-- 底部点击弹出栏 -->
    <div class>
      <van-goods-action>
        <van-goods-action-icon icon="chat-o" text="客服" color="#07c160" />
        <van-goods-action-icon icon="cart-o" text="购物车" @click="toCart" />
        <van-goods-action-icon icon="star" text="已收藏" color="#ff5000" />
        <van-goods-action-button type="warning" text="加入购物车" @click="showData" />
        <van-goods-action-button type="danger" text="立即购买" @click="showData" />
      </van-goods-action>
    </div>
    <!-- 弹出的商品规格 -->
    <div class>
      <van-action-sheet v-model="show" @closed="OnClosed()">
        <div class="content">
          <!-- 弹出框的头部 -->
          <div class="popup_header">
            <div class="popup_img">
              <img :src="item.basicInfo.pic" alt />
            </div>
            <div class="popup_message">
              <div class="item_name" v-html="item.basicInfo.name"></div>
              <div class="item_price">￥{{item.basicInfo.minPrice}}</div>
            </div>
          </div>
          <!-- 弹出框选项信息 -->
          <div class="popup_seleect_container">
            <!-- 颜色 -->
            <div class="select_title">{{item.properties.name}}</div>
            <div class="select_option">
              <div
                :class="colorSelect===num?'color_option_active':'color_option'"
                v-for="(ele,num) in item.color"
                :key="num"
                @click="onColor(num)"
              >{{ele}}</div>
            </div>
            <!-- 数量 -->
            <div class="select_title">选择数量</div>
            <div class="select_option">
              <div class="total_count">
                <div @click="OnMinus(item)">-</div>
                <div class="count_container">{{item.basicInfo.minBuyNumber}}</div>
                <div @click="OnPlus(item)">+</div>
              </div>
            </div>
            <!-- 确认按钮 -->
            <div class="enter_button">
              <div></div>
              <div class="enter_button_wrapper">
                <button @click="addCart(item)">确定</button>
              </div>
            </div>
          </div>
        </div>
      </van-action-sheet>
    </div>

  </div>
</template>

<script>
export default {
  data() {
    return {
      show: false
      // colorSelect: -1
    };
  },
  computed: {
    item() {
      return this.$store.state.detailsModules.detailsItem;
      // return JSON.parse(localStorage.getItem("details"));
    }
  },
  methods: {
    showData() {
      this.show = true;
    },
    OnClosed() {
      this.show = false;
    },
    // onColor(num) {
    //   this.colorSelect = num;
    // },
    OnPlus(item) {
      item.basicInfo.minBuyNumber++;
    },
    OnMinus(item) {
      if (item.basicInfo.minBuyNumber > 0) {
        item.basicInfo.minBuyNumber--;
      }
    },
    toCart() {
      this.$router.push("/cart");
    },
    addCart(item) {
      this.$store.dispatch("addCartItems", item);
      this.show = false;
    }
  },
  mounted() {}
};
</script>

<style scoped>
.details_container {
  width: 100%;
}
.details_swiper {
  width: 100%;
  height: 8rem;
  background-color: #fff;
}
.details_swiper img {
  width: 100%;
  height: 8rem;
}
.details_message_container {
  width: 100%;
  /* height: 2.2rem; */
  margin-top: 0.2rem;
  display: inline-flex;
  justify-content: center;
  align-items: center;
}
.details_message_wrapper {
  width: 96%;
  height: 2.2rem;
  padding: 0.1rem 0rem;
}
.details_message_name {
  width: 100%;
  height: 0.8rem;
  display: inline-flex;
  justify-content: flex-start;
  align-items: center;
  font-size: 0.32rem;
}
.details_message_title {
  width: 100%;
  height: 0.5rem;
  display: inline-flex;
  justify-content: flex-start;
  align-items: center;
  color: gray;
}
.details_message_box {
  width: 100%;
  height: 0.5rem;
  display: inline-flex;
  justify-content: space-between;
  align-items: center;
}
.details_message_price {
  width: 20%;
  color: red;
  font-size: 0.28rem;
}
.details_message_gray {
  display: inline-flex;
  justify-content: space-between;
  align-items: center;
  width: 80%;
  color: gray;
}
.gray_line {
  width: 100%;
  height: 0.2rem;
  background-color: #f5f5f5;
}
.details_main_container {
  width: 100%;
}
.details_button_container {
  width: 100%;
  display: inline-flex;
  justify-content: center;
  align-items: center;
}
.details_button_container div {
  width: 50%;
  height: 1rem;
  display: inline-flex;
  justify-content: center;
  align-items: center;
  font-size: 0.3rem;
}
.details_button_container .details_introduce_button {
  /* width: ; */
  border-bottom: 0.06rem solid red;
}
.details_introduce_content {
  width: 100%;
  overflow: hidden;
}

.content {
  /* width: 100%; */
  height: 450px;
}
.popup_header {
  width: 100%;
  height: 120px;
  background-color: #f9f9f9;
  display: inline-flex;
  justify-content: space-around;
  align-items: center;
}
.popup_img {
  width: 25%;
  height: 90px;
}
.popup_img img {
  width: 100%;
  height: 90px;
}
.popup_message {
  width: 60%;
  height: 90px;
}
.popup_message .item_name {
  width: 100%;
  height: 50px;
}
.popup_message .item_title {
  height: 20px;
}
.popup_message .item_price {
  height: 20px;
  color: red;
}
.popup_seleect_container {
  width: 100%;
  height: 120px;
}

.popup_seleect_container {
  width: 100%;
  height: 120px;
}
.select_title {
  /* margin: 0 auto; */
  width: 100%;
  text-indent: 5%;
  height: 40px;
  display: inline-flex;
  justify-content: flex-start;
  align-items: center;
  font-size: 18px;
  font-weight: 700;
  border-bottom: 1px solid #eeeeee;
}
.select_option {
  width: 100%;
  height: 80px;
  border-bottom: 1px solid #eeeeee;
  display: inline-flex;
  justify-content: flex-start;
  align-items: center;
}
.color_option {
  width: 16%;
  height: 40px;
  border: 1px solid #eee;
  margin-left: 5%;
  display: inline-flex;
  justify-content: center;
  align-items: center;
  border-radius: 5px;
}
.color_option_active {
  width: 16%;
  height: 40px;
  border: 1px solid skyblue;
  margin-left: 5%;
  display: inline-flex;
  justify-content: center;
  align-items: center;
  border-radius: 5px;
  font-weight: 700;
}
.total_count {
  display: inline-flex;
  margin-left: 5%;
}
.total_count div {
  width: 30px;
  height: 30px;
  display: inline-flex;
  justify-content: center;
  align-items: center;
  border: 1px solid gray;
  font-weight: 700;
  color: black;
}
.total_count .count_container {
  width: 50px;
}
.enter_button {
  width: 100%;
  height: 60px;
  border-top: 1px solid #eee;
  position: fixed;
  left: 0px;
  bottom: 0px;
  display: inline-flex;
  justify-content: space-between;
  align-items: center;
}
.enter_button_wrapper {
  width: 75%;
  height: 40px;
  margin-right: 5%;
}
.enter_button_wrapper button {
  width: 100%;
  height: 40px;
  background-color: rgb(57, 103, 230);
  border: 0px;
  border-radius: 5px;
  font-weight: 700;
  color: #fff;
}

</style>